<docs>
  ## 编辑求职意向
</docs>
<template>
  <div class="wrap">
    <co-form :model="data" :rules="rules" ref="form" label="求职意向信息">
      <edit-select prop="gwfl" label="岗位分类" v-model="data.gwfl" @selectValue="checkVal" :xsqb="xsqbgw"></edit-select>
      <editback-select
        prop="gwlmbh"
        label="岗位类目"
        @click="qhgw"
        v-model="data.gwlmbh"
        :class="{'btnDisabled':mu_isAble}"
        :Interface="lm_list"
      ></editback-select>
      <!-- 列表 ---接口查询 -->
      <editback-select
        ref="qzgw_xl"
        prop="gwbm"
        v-if="xl_flag"
        :class="{'btnDisabled':xl_isAble}"
        label="求职岗位"
        v-model="data.gwbm"
        :Interface="gw_list"
      ></editback-select>
      <!-- 模糊查询 -->
      <co-position
        label="求职岗位"
        v-if="mu_flag"
        v-model="data.gwmc"
        prop="gwmc"
        :cyjk="cymujk"
        :gwbh.sync="data.gwmc"
        ref="qzgw"
        @lm_arr="lm_arr"
      ></co-position>

      <co-select
        prop="ygxs"
        label="用工形式"
        disabled
        v-model="data.ygxs"
        :list="codeTable.zyjs_d_dwygxs"
      ></co-select>
      <co-input prop="zdyx" v-if="yx" label="期望最低月薪" v-model="data.zdyx" placeholder="请输入最低月薪"></co-input>
      <co-input
        prop="zgyx"
        v-if="yx"
        label="期望最高月薪"
        type="tel"
        v-model="data.zgyx"
        placeholder="请输入最高月薪"
      ></co-input>
      <co-input prop="zdsx" v-if="sx" label="期望最低时薪" v-model="data.zdsx" placeholder="请输入最低时薪"></co-input>
      <co-input
        prop="zgsx"
        v-if="sx"
        label="期望最高时薪"
        type="tel"
        v-model="data.zgsx"
        placeholder="请输入最高时薪"
      ></co-input>

      <co-select prop="qwqyxz" label="期望企业性质" v-model="data.qwqyxz" :list="codeTable.cdl_orgtype"></co-select>
      <co-level-picker
        prop="qwdjzclx"
        v-if="zclx"
        label="期望登记注册类型"
        table-name="cdg_regtype"
        v-model="data.qwdjzclx"
        show-type="2"
        :name="qwdjzclx_xs"
      ></co-level-picker>
      <co-select
        v-if="qtzclx"
        label="其他登记注册类型"
        v-model="data.qtdjzclx"
        prop="qtdjzclx"
        :list="codeTable.cdl_orgtype_01"
      ></co-select>

      <co-level-picker
        label="单位行业"
        prop="qwcshy"
        v-model="data.qwcshy"
        :name="qwcshy_xs"
        table-name="cdg_industry_all"
        show-type="2"
      ></co-level-picker>
      <co-select label="工作地区" :list="codeTable.zyjs_d_gzdq" prop="qwjydq" v-model="data.qwjydq"></co-select>
      <co-input prop="qwjydd" label="工作地点" v-model="data.qwjydd" placeholder="请输入工作地点"></co-input>
    </co-form>
    <div class="btn-wrap">
      <button class="weui-btn weui-btn_primary" @click.prevent="save" type="button">保存</button>
      <button class="weui-btn weui-btn_default" @click="backBase" type="button">返回</button>
    </div>
  </div>
</template>
<script>
import coForm from "base/form/form";
import coInput from "base/form/input";
import coSelect from "base/form/select";
import { validator } from "common/js/valid";
import coLevelPicker from "base/form/levelPicker";
import coPosition from "base/form/position";
import editSelect from "base/form/editSelect";
import editbackSelect from "base/form/editbackSelect";

export default {
  name: "editJobIntent",
  components: {
    coForm,
    coInput,
    coSelect,
    coLevelPicker,
    coPosition,
    editSelect,
    editbackSelect
  },
  data() {
    return {
      cymujk: "",//常用模糊接口
      sfzjsx: false, //开始就刷新禁止更改mc
      lmFlag: false, //判断选择模糊查询求职岗位后再点击岗位类目后不清空求职岗位
      xsqbgw: "", //显示全部岗位
      xl_isAble: true,
      mu_isAble: false,
      mu_flag: true, //全部岗位模糊显示
      xl_flag: false, //全部岗位下拉显示
      gw_list: [], //岗位
      lm_list: [], //类目
      gwfl_arr: [
        { dmid: "01", dmmc: "常用岗位" },
        { dmid: "02", dmmc: "全部岗位" }
      ],
      data: {
        gwfl: "", //岗位分类
        gwlmbh: "", //岗位类目
        qzyxid: "", // 求职意向id
        grqzid: "", // 个人求职id
        qwqyxz: "", // 企业性质
        qwcshy: "", // 单位行业
        qwjydq: "", // 工作地区
        qwjydd: "", // 工作地点
        ygxs: "", // 用工形式
        gwmc: "", // 岗位名称
        gwbm: "", // 岗位编码
        zdyx: "", // 期望最低薪资
        zgyx: "", // 期望最高薪资
        zdsx: "", // 最低时薪
        zgsx: "", // 最高时薪
        qwdjzclx: "", // 期望登记注册类型
        qtdjzclx: "", // 其他登记注册类型
        ywcz: ""
      },
      rules: {
        gwmc: validator("64,least,岗位名称,true"),
        gwfl: validator("64,full,岗位分类,false"), // 岗位分类
        gwlmbh: validator("32,full,岗位类目,true"), // 岗位类目
        gwbm: validator("64,least,求职岗位,false"), // 岗位名称
        qwqyxz: validator('2,"full","期望企业性质",false'), // 企业性质
        qwcshy: validator('5,"full","单位行业",true'), // 单位行业
        qwjydq: validator('12,"full","工作地区",false'), // 工作地区
        qwjydd: validator('128,"full","工作地点",true'), // 工作地点
        ygxs: validator('2,"full","用工形式",false'), // 用工形式
        zdyx: validator('7,"number","最低月薪",true', (rules, value, cb) => {
          const { bjszdyx } = this;
          if (!value && !this.data.zgyx) {
            cb(new Error("最低与最高月薪不能都为空"));
          } else if (+value < bjszdyx) {
            cb(new Error(`最低月薪不能低于北京市最低工资${bjszdyx}`));
          } else {
            cb();
          }
        }), // 期望最低薪资
        zgyx: validator('7,"number","最高月薪",true', (rules, value, cb) => {
          if (!value && !this.data.zdyx) {
            cb(new Error("最低与最高月薪不能都为空"));
          } else {
            cb();
          }
        }), // 期望最高薪资
        zdsx: validator('7,"number","最低时薪",true', (rules, value, cb) => {
          if (!value && !this.data.zgsx) {
            cb(new Error("最低与最高时薪不能都为空"));
          } else {
            cb();
          }
        }), // 最低时薪
        zgsx: validator('7,"number","最高时薪",true', (rules, value, cb) => {
          if (!value && !this.data.zdsx) {
            cb(new Error("最低与最高时薪不能都为空"));
          } else {
            cb();
          }
        }), // 最高时薪
        qwdjzclx: validator('3,"full","期望登记注册类型",false'), // 期望登记注册类型
        qtdjzclx: validator('3,"full","其他登记注册类型",false') // 其他登记注册类型
      },
      codeTable: {
        zyjs_d_dwygxs: [], // 用工形式
        zyjs_d_gzdq: [], // 工作地区
        cdl_orgtype: [], // 单位性质
        // cdg_regtype: [], // 期望登记注册类型
        cdl_orgtype_01: [], // 其他登记注册类型
        cdg_industry_all: [] // 单位行业
      },
      bjszdyx: "", // 北京市最底薪资
      gzdq_xs: "",
      qwdjzclx_xs: "",
      qwcshy_xs: "",
      visible: false,
      visibleSuggestion: false,
      qtzclx: false,
      zclx: false,
      yx: true,
      sx: false
    };
  },
  watch: {
    "data.qwqyxz": function watcher(val) {
      if (val === "90") {
        this.qtzclx = true;
      } else {
        this.qtzclx = false;
      }
      if (val === "10") {
        this.zclx = true;
      } else {
        this.zclx = false;
      }
    },
    "data.ygxs": function watcher(val) {
      if (val === "40") {
        this.sx = true;
        this.yx = false;
      } else {
        this.sx = false;
        this.yx = true;
      }
    },
    "data.gwlmbh": function watcher(val) {
      if (this.lmFlag) {
        return false
      }
      if (val) {
        this.mu_flag = false;
        this.xl_flag = true;
      } else {
        this.mu_flag = true;
        this.xl_flag = false;
      }
      this.data.gwmc = "";
      if (val) {
        this.$http
          .get("/dmbgl/cygwCx", {
            params: {
              gwbh: val
            }
          })
          .then(res => {
            // this.data.gwmc = res.returnData.tsgwxx
            if (res.returnData.tsgwxx) {
              this.gw_list = res.returnData.tsgwxx;
              this.xl_isAble = false;
            }
          });
      }
    }
  },
  methods: {
    lm_arr(arr) {
      this.sfzjsx = true
      if (this.data.gwfl == "02") {
        this.mu_isAble = true;
        this.lmFlag = true;
        if (arr && arr.length > 1) {
          this.data.gwlmbh = ""
          this.lm_list = arr;
          this.mu_isAble = false;
        } else if (arr && arr.length == 1) {
          this.lm_list = arr
          this.data.gwlmbh = arr[0].gwbh;
        } else {
          this.data.gwlmbh = ""
        }
      }  else {
        this.mu_isAble = false;
        if (arr) {
          this.data.gwlmbh = arr[0].gwbh;
          this.lmFlag = true //禁止跳转
        } else {
          this.data.gwlmbh = ""
        }
      }

    },
    /* 获取代码表 */
    GET_codeTable() {
      const arrTableName = Object.keys(this.codeTable);
      this.$http
        .get("/dmbgl/dmblbCx", {
          params: {
            table_name: arrTableName.join()
          }
        })
        .then(res => {
          this.getCodeTabled = true;
          const data = res.returnData.dmblb;
          arrTableName.forEach(item => {
            this.codeTable[item] = data[item];
          });
        });
    },
    inputSuggestion() {
      this.visibleSuggestion = true;
    },
    backBase() {
      this.$router.go(-1);
    },
    save() {
      this.$refs.form.validate(() => {
        if (this.mu_flag && this.sfzjsx) {
          this.data.gwbm = this.data.gwmc
          this.data.gwmc = this.$refs.qzgw.labelName
        }else {
          if (this.data.gwbm) {
            this.gw_list.map((item,i)=>{
              if (this.data.gwbm == item.gwbh) {
                return this.data.gwmc = item.gwmc
              }
            })
          }
        }

        this.$loading = true;
        this.$http
          .post("/grgl/qzyxBc", this.data)
          .then(res => {
            const resData = res.returnData;
            this.$alert(resData.message, () => {
              const code = +resData.executeResult;
              if (code) {
                this.backBase();
              }
            });
          })
          .finally(() => {
            this.$loading = false;
          });
      });
    },
    //类目接口
    getLmseam() {
      this.$http.get("/dmbgl/cygwCx").then(res => {
        this.lm_list = res.returnData.tsgwxx;
      });
    },
    //点击取消选择求职岗位
    qhgw() {
      if(this.data.gwfl == "01"){
        this.lmFlag = false
      }
    },
    //切换常用，全部岗位切换
    checkVal(val) {
      this.sfzjsx = true
      this.lmFlag = false;
      this.data.gwlmbh = "";
      this.data.gwbm = ""
      this.lm_list = [];
      this.mu_flag = true;
      this.xl_flag = false;
      if (val == "02") {
        //全部岗位
        this.xl_isAble = false;
        this.mu_isAble = true;
        this.cymujk = '' //常用模糊接口切换
      } else {
        // 类目
        this.cymujk = '1' //常用模糊接口切换
        this.getLmseam();
        this.xl_isAble = true;
        this.mu_isAble = false;
      }
        this.data.gwmc = ""
        if (this.$refs.qzgw) {
          this.$refs.qzgw.labelName = ''
          const child_ref = this.$refs.qzgw.$refs.inS;
          child_ref.position=[]
          child_ref.gwmc = ""
          child_ref.isFirst = true
        }
    }
  },
  created() {
    // 类目
    this.getLmseam();
    // 获取代码表
    this.getCodeTabled = false;
    this.GET_codeTable();
    // 赋值
    var qzyx = this.$route.query;
    // 为零则为常用岗位 1是全部
    if (qzyx.sfqb == 1) {
      this.cymujk = '' //常用模糊接口切换
      this.mu_isAble = true;
      this.xsqbgw = "1"; //岗位分类显示全部标识
    } else {
      this.cymujk = '1' //常用模糊接口切换
    }
    if (qzyx.ywcz == 2) {
      Object.keys(this.data).forEach(item => {
        this.data[item] = qzyx[item];
      });
    } else {
      this.data.ywcz = qzyx.ywcz;
      this.data.grqzid = qzyx.grqzid;
    }

    // 行政区划显示
    this.bjszdyx = this.$route.params.bjszdyx;
    this.gzdq_xs = qzyx.gzdq_xs;
    this.qwcshy_xs = qzyx.qwcshy_xs;
    this.qwdjzclx_xs = qzyx.qwdjzclx_xs;
    // this.jzdxzqh_xs = data.jzdxzqh_xs;
    // 隐藏home按钮
    this.$store.commit("SET_VISIBLE_ALL", false);
  }
};
</script>
<style scoped lang="scss">
@import "~common/scss/var.scss";
.wrap {
  .btn-wrap {
    display: flex;
    .weui-btn {
      margin: $margin-base auto;
      flex: 0 1 47%;
    }
  }
}

.btnDisabled {
  opacity: 0.5;
  pointer-events: none;
}
.btnDisabled:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1px solid #ccc;
  color: #e5e5e5;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
  left: 30px;
  z-index: 2;
}
</style>

